package com.itheima.service.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    //运营数据导出
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //报表日期
        String date = DateUtils.parseDate2String(DateUtils.getToday());
        //获得本周一日期
        String week = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获得本月第一天日期
        String month = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //本日新增会员数
        Integer todayNewMember = memberDao.findMemberCountByDate(date);
        //总会员数
        Integer totalMember = memberDao.findMemberTotalCount();
        //本周新增会员数
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(week);
        //本月新增会员数
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(month);

        //本日预约数
        Integer todayOrderNumber = orderDao.findOrderCountByDate(date);
        //本周预约数
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(week);
        //本月预约数
        Integer thisMonthOrderNumber = orderDao.findVisitsCountByDate(month);

        //今日到诊数
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(date);
        //本周到诊数
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(week);
        //本月到诊数
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(month);

        //热门套餐查询
        List<Map> hotSetmeal = orderDao.findHotSetmeal();

        Map<String,Object> result = new HashMap<>();
        result.put("reportDate",date);
        result.put("todayNewMember",todayNewMember);
        result.put("totalMember",totalMember);
        result.put("thisWeekNewMember",thisWeekNewMember);
        result.put("thisMonthNewMember",thisMonthNewMember);
        result.put("todayOrderNumber",todayOrderNumber);
        result.put("thisWeekOrderNumber",thisWeekOrderNumber);
        result.put("thisMonthOrderNumber",thisMonthOrderNumber);
        result.put("todayVisitsNumber",todayVisitsNumber);
        result.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        result.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        result.put("hotSetmeal",hotSetmeal);
        return result;
    }
}
